@extends('admin.common.base-master')

@section('html-head')
    <link href="{{url('css/admin/pagenum.css')}}" rel="stylesheet" />

@endsection

@section('html-body')
    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <a href="#">积分管理</a>
            <em> > </em>
            <a href="{{route('Admin.Home.qrCodeList')}}">二维码列表</a>
        </div>

        @include('admin.common.integral-header')

        <div class="filter-box clearfix">

            <div class="fr">
                <a class="addBtn" href="{{route("Admin.Home.qrCodSet")}}">新增</a>
            </div>
        </div>
        <div class="table-box">
            <table class="table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>二维码key</th>
                    <th>链接</th>
                    <th>是否使用</th>
                    <th>使用时间</th>
                    <th>积分</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @if(count($qrCodes) > 0)
                    @foreach($qrCodes as $qrCode)
                        <tr id="qrcode_{{$qrCode->id}}">
                            <td>{{$qrCode->id}}</td>
                            <td>{{$qrCode->q_key}}</td>
                            <td>{{$qrCode->url}}</td>
                            <td>
                                @if($qrCode->is_use == 1)
                                    已使用
                                @else
                                    未使用
                                @endif
                            </td>
                            <td>{{$qrCode->use_time}}</td>
                            <td>{{$qrCode->integral}}</td>
                            <td>
                                @if($qrCode->status == 1)
                                    显示
                                @else
                                    隐藏
                                @endif
                            </td>
                            <td><a class="color2" href="{{route("Admin.Home.qrCodSet")}}?id={{$qrCode->id}}">编辑</a> <span>|</span> <a href="javascript:void(0);" class="del" data-id="{{$qrCode->id}}">删除 </a></td>
                        </tr>
                    @endforeach
                @endif
                </tbody>
            </table>
        </div>
        <?php echo $qrCodes->render(); ?>
    </div>
    <script>
        $(function(){

            $(document).on("click",".del",function(){
                var id = $(this).attr("data-id");

                noty({
                    text: '你确定要删除吗?',
                    buttons: [
                        {addClass: 'btn btn-primary', text: '确定', onClick: function($noty) {
                            $noty.close();
                            $.ajax({
                                url:'{{route('Api.Admin.sys.delQrCode')}}',
                                type:'post',
                                dataType:'json',
                                data:{id:id},
                                success:function(obj){
                                    if(obj.level == "success"){
                                        $("#qrcode_"+id).hide('slow');
                                    }else{
                                        noty({type:obj.level,text:obj.message,timeout:600});
                                    }
                                },
                                error:function(obj){
                                    console.log(obj);
                                }

                            });
                        }
                        },
                        {addClass: 'btn btn-danger', text: '取消', onClick: function($noty) {
                            $noty.close();
                        }
                        }
                    ]
                });

            });
        });
    </script>
@endsection